<?php
require_once realpath (dirname (__FILE__) . '//..//pages.php');
require_once CLASS_USER;
require_once INC_FUNCTIONS;
require_once INC_MESSAGES;
require_once MDL_TABLES;

if (isset ($_SESSION[KEY_SESSION_USER])) {
    $user = unserialize ($_SESSION[KEY_SESSION_USER]);
    $logged = $user->isRegistered ();
} else {
    $logged = false;
}
if (isset ($request)) {
    $tables = getTables ();
} else if (isset ($stat)) {
    $tables = getStats();
}
echo doctype ();
?>
<html>
    <?php echo head (PAGE_TITLE, array (HTTP_CSS_TABLES, HTTP_CSS_MENU, HTTP_CSS_STYLE)); ?>
    <body>
        <?php
        require_once VW_MENU;
        if (!isset ($request) && !isset ($stat)) :
            ?>
            No mode set!
        </div>
    </body>
    </html>
    <?
    exit ();
endif;
if (!$logged) :
    ?><div class="message">
        <?php echo MSG_NOT_AUTHORIZED; ?>
    </div>
    </body>
    </html>
    <?php
    exit ();
endif;
?>
<div id="tables">
    <ul>
        <?php
        if (isset ($request)) :
            foreach ($tables as $key => $tab) :
                if ($user->can ($request, $key)) :
                    ?>
                    <li><a href="<?php echo HTTP_CTRL_MAIN ?>?request=<?php echo $request; ?>&table=<?php echo $key; ?>"><?php echo $tab; ?></a></li>
                    <?php
                endif;
            endforeach;
        endif;
        ?>
        <?php if (isset ($stat)) : foreach ($tables as $key => $tab) : ?>
                <li><a href="<?php echo HTTP_CTRL_MAIN ?>?stat=<?php echo $key; ?>"><?php echo $tab; ?></a></li>
                <?php
            endforeach;
        endif;
        ?>
    </ul>
</div>
</body>
</html>
